package com.cn.wanxi.servlet.manage.nav;

import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.impl.NavServiceImpl;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/navDelete")
public class NavDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.拿到页面的值
        String idString = req.getParameter("id");
        //因为id类型为Integer，所以需要进行强制转换
        Integer id = idString == null ? 0 : Integer.parseInt(idString);
//        2.封装对象
        NavModel navModel = new NavModel();
        navModel.setId(id);
//        3.调用服务逻辑层
        INavService iNavService=new NavServiceImpl();
        int num=iNavService.del(navModel);
//        4.返回数据
        JSONArray jsonArray=JSONArray.fromObject(num);
        resp.getWriter().println(jsonArray);
    }
}
